package cn.yto.wdgj.wdgjgptdigitaltool.controller;


import cn.yto.response.BaseResponse;
import cn.yto.response.DataResult;
import cn.yto.wdgj.common.reponse.MutiResponse;
import cn.yto.wdgj.wdgjgptdigitaltool.entity.dto.request.GptCaseMaintenanceRequest;
import cn.yto.wdgj.wdgjgptdigitaltool.entity.dto.response.GptCaseMaintenanceResponse;
import cn.yto.wdgj.wdgjgptdigitaltool.service.GptCaseMaintenanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping(value = "/case")
@Api(value = "测试用例", tags = {"测试用例"})
public class GptCaseMaintenanceController {

    @Autowired
    private GptCaseMaintenanceService gptCaseMaintenanceService;

    @RequestMapping(value = "/getPage", method = RequestMethod.POST)
    @ApiOperation(value = "分页查询测试用例", httpMethod = "POST", notes = "分页查询测试用例")
    public DataResult<MutiResponse<GptCaseMaintenanceResponse>> getPage(@RequestBody GptCaseMaintenanceRequest gptCaseMatcherRequest) {
        try {
            return gptCaseMaintenanceService.getAllGptCaseMaintenance(gptCaseMatcherRequest);
        } catch (Exception e) {
            log.error("/getPage", e);
            return DataResult.fail(e.getMessage());
        }
    }

    @RequestMapping(value = "/del", method = RequestMethod.GET)
    @ApiOperation(value = "删除测试用例", httpMethod = "GET", notes = "删除测试用例")
    public DataResult<BaseResponse> del(@RequestParam("id") Long caseId) {
        try {
            return gptCaseMaintenanceService.delGptCaseMaintenance(caseId);
        } catch (Exception e) {
            log.error("/del", e);
            return DataResult.fail(e.getMessage());
        }
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "更新测试用例", httpMethod = "POST", notes = "更新测试用例")
    public DataResult<BaseResponse> update(@RequestBody GptCaseMaintenanceRequest gptCaseMatcherRequest) {
        try {
            return gptCaseMaintenanceService.updateGptCaseMaintenance(gptCaseMatcherRequest);
        } catch (Exception e) {
            log.error("/update", e);
            return DataResult.fail(e.getMessage());
        }
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "新增测试用例", httpMethod = "POST", notes = "新增测试用例")
    public DataResult<BaseResponse> save(@RequestBody GptCaseMaintenanceRequest gptCaseMatcherRequest) {
        try {
            return gptCaseMaintenanceService.saveGptCaseMaintenance(gptCaseMatcherRequest);
        } catch (Exception e) {
            log.error("/save", e);
            return DataResult.fail(e.getMessage());
        }
    }
}
